{extend name='base' /}

{block name='main'}
<style>
    .correlation {
        color: #666;
        padding: 30px 0 10px 0;
        font-size: 12px;
    }

    .correlation span {
        margin: 0 5px;
    }

    .condition_box p {
        line-height: 25px;
        padding: 20px 0;
        border-bottom: 1px dashed #dcdcdc;
        margin: 0;
    }

    .condition_box .classify_con em,.condition_box .price_con em,.condition_box .type_con em {
        color: #333;
        font-style: normal;
    }

    .condition_box .classify_con span,.condition_box .price_con span,.condition_box .type_con span {
        margin-left: 25px;
        cursor: pointer;
        color: #666
    }

    .condition_box .classify_con span.cur,.condition_box .price_con span.cur,.condition_box .type_con span.cur {
        color: #fff;
        background: #00c29a;
        padding: 4px 10px;
        border-radius: 3px
    }

    .list {
        padding: 38px 0 38px 10px;
        border-bottom: 1px dashed #dcdcdc;
        position: relative
    }

    .list .newbtn_box a {
        width: 108px;
        height: 26px;
        text-align: center;
        line-height: 26px;
        display: block;
        margin-left: 15px;
        float: left
    }

    .list .book_pic {
        width: 115px;
        height: 165px;
        float: left;
        display: block;
        margin-right: 26px
    }

    .list .detail_con {
        position: relative;
        /*width: 775px;*/
        /*float: left*/
    }

    .list .detail_con p{
        line-height: 18px;
    }

    .list .detail_con .text_con {
        height: 38px;
        margin-bottom: 30px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-height: 18px !important;
    }

    .list .detail_con .author,.list .detail_con .title {
        margin-bottom: 20px
    }

    .list .detail_con .title a {
        color: #333;
        font-size: 16px;
        font-weight: 700;
        text-decoration: none;
    }

    .list .detail_con .author a {
        color: #888;
        font-size: 12px;
        text-decoration: none;
    }

    .list .detail_con .text_con a {
        color: #999;
        font-size: 14px;
        text-decoration: none;
        line-height: 18px !important;
    }

    .list .detail_con .price a {
        color: #ee554a;
        font-size: 16px;
        text-decoration: none;
    }

    .list .detail_con .price a del {
        color: #666;
        margin-left: 10px
    }

    .list .detail_con .green_btn {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 110px;
        height: 30px;
        display: block;
        text-align: center;
        line-height: 30px;
        float: left;
        cursor: pointer;
        font-size: 14px;
        background-color: #ff2f2f;
        color: #fff;
        box-sizing: content-box;
    }

    .list .detail_con .green_btn:hover {
        background-color: #eb2323
    }

    .sort_con {
        border: 1px solid #ebe6e1;
        width: 930px;
        height: 32px;
        margin-top: 20px;
        background: #f5f5f5
    }

    .sort_con em {
        color: #333;
        float: left;
        line-height: 32px;
        height: 32px;
        padding-left: 12px;
        font-size: 12px;
        font-style: normal;
    }

    .sort_con span {
        width: 60px;
        height: 32px;
        line-height: 32px;
        float: left;
        cursor: pointer;
        text-align: center;
        color: #7e7e7e;
        font-size: 12px;
    }

    .sort_con span.cur {
        color: #24c6a1;
    }

    .sort_con span.cur i {
        background-image: url(__IMG__/green_down.png);
        background-position: 0 0;
        background-size: 100% 100%
    }

    .sort_con span i {
        margin-left: 5px;
        width: 10px;
        height: 10px;
        display: inline-block;
        background-image: url(__IMG__/grey_down.png);
        background-position: 0 0;
        background-size: 100% 100%
    }
    .empty_box {
        margin: 60px 0 0 235px;
        width: 460px;
        font-size: 12px;
    }

    .empty_box img {
        vertical-align: middle
    }

    .btn_add_to_cart:hover{
        text-decoration: none;
    }
</style>
<div class="row m-0" style="display: inherit;">
    <!--搜索条件-->
    <p class="correlation" id="correlation">共<em>{$total}</em>条 <span>{$keyword}</span>相关的搜索结果</p>
    <!--<div class="condition_box">-->
        <!--<p class="price_con" id="priceStage">-->
            <!--<em>价格：</em>-->
            <!--<span data-price="-1" class="cur">全部</span>-->
            <!--<span data-price="0">免费</span>-->
            <!--<span data-price="1">1元以下</span>-->
            <!--<span data-price="2">1-10元</span>-->
            <!--<span data-price="3">10元以上</span>-->
        <!--</p>-->
        <!--<p class="type_con" id="typeStage">-->
            <!--<em>类型：</em>-->
            <!--<span data-type="-1" class="cur">全部</span>-->
            <!--<span data-type="0">出版物</span>-->
        <!--</p>-->
        <!--<p class="classify_con" id="classifyStage">-->
            <!--<em>分类：</em>-->
            <!--<span data-code="zidingyi" class="cur">全部</span>-->
            <!--<span data-code="DDDS-DZS-JG">经管/励志</span>-->
        <!--</p>-->
    <!--</div>-->
    <p class="sort_con clearfix" id="reorder">
        <em>排序：</em>
        <a href="{:url('Book/search')}?keyword={$keyword}&order=id"><span class="{if $order=='id'}cur{/if}" data-sort="-1">综合</span></a>
        <a href="{:url('Book/search')}?keyword={$keyword}&order=orders"><span class="{if $order=='orders'}cur{/if}">销量<i class="arrow_icon icon"></i></span></a>
        <a href="{:url('Book/search')}?keyword={$keyword}&order=update_entered"><span class="{if $order=='update_entered'}cur{/if}">时间<i class="arrow_icon icon"></i></span></a>
    </p>
    <!--列表-->
    <div id="conditionList" class="mb-4">
        {foreach $list as $k => $v}
        <div class="list book_list_wrap clearfix">
            <a target="_blank" href="{:url('Book/info', array('bookid' => $v['id']))}">
                <img class="book_pic" src="{$v['thumb']}">
            </a>
            <div class="detail_con">
                <p class="title"><a target="_blank" href="{:url('Book/info', array('bookid' => $v['id']))}">{$v['bname']}</a>
                </p>
                <p class="author">
                    <a href="{:url('Book/info', array('bookid' => $v['id']))}">{$v['author']}</a>
                </p>
                <p class="text_con">
                    <a href="{:url('Book/info', array('bookid' => $v['id']))}">{$v['content']}</a>
                </p>
                <p class="price m-0">
                    <a target="_blank" href="{:url('Book/info', array('bookid' => $v['id']))}">
                        ￥{$v['price']}
                        <!--<del>￥59.80</del>-->
                    </a>
                </p>
                <a href="javascript:void(0)" class="green_btn btn_add_to_cart" data-bookid="{$v['id']}" data-status="{if session('userid')}1{else}0{/if}">加入购物车</a>
            </div>
        </div>
        {/foreach}
        {if count($list) == 0}
        <div class="empty_box" id="empty_page">
            <img src="__IMG__/empty_page.jpg">
            没有找到相关书籍，换个词试试吧！
        </div>
        {/if}
    </div>
    <!--分页-->
    <nav aria-label="Page navigation example" style="clear: both;">
        {$page|raw}
    </nav>
</div>
{/block}

{block name='js'}
<script>
    $(function () {
       let lock = false;
       $(".btn_add_to_cart").on('click', function () {
           let status = $(this).data('status');
           let bookid = $(this).data('bookid');
           if (status == 0) {
               window.location.href = "{:url('User/login')}";
               return;
           }else{
               if (lock){
                   return;
               }
               lock = true;
               $.post("{:url('Cart/add')}", {bookid: bookid}, function (res) {
                   if (res.code == 0) {
                       swal("提示", res.msg, {
                           icon : "error",
                           buttons: {
                               confirm: {
                                   className : 'btn btn-danger',
                                   text : '确定',
                               }
                           },
                       });
                   }else{
                       swal("提示", res.msg, {
                           icon : "success",
                           buttons: {
                               confirm: {
                                   className : 'btn btn-success',
                                   text : '确定',
                               }
                           }
                       }).then(function () {
                           $("#cart_num").html(res.data);
                       });
                   }
                   lock = false;
               }, 'json');
           }
       });
    });
</script>
{/block}